<template>
	<view style="width:100%">
		<!-- 		<Navigate :title="title"/> -->
		<Address :address="order_info.address" :mobile="order_info.mobile" :consignee="order_info.consignee" />
		<Order :order_sn="order_info.order_sn" :goods_name="order_info.goods_name" :original_img="order_info.original_img" :shop_price="order_info.shop_price" />
		<Balance :total_amount="order_info.total_amount" :goods_price="order_info.goods_price" :user_money="user_money" />
		<Submit @click="submit" />
	</view>
</template>

<script>
import Navigate from '@/components/Navigate/index.vue';
import Address from '../../components/Address/index.vue';
import Order from '../../components/Order/index.vue';
import Balance from '../../components/Balance/index.vue';
import Submit from '../../components/Submit/index.vue';
import fetch from '@/common/fetch.js';
export default {
	components: {
		Navigate,
		Address,
		Order,
		Balance,
		Submit
	},
	data() {
		return {
			title: 'Confirm order',
			user_money: 0,
			form: {},
			order_info: {
				order_id: 0,
				order_sn: '',
				mobile: '',
				total_amount: 0,
				goods_name: '',
				shop_price: 0,
				original_img: '',
				consignee: '',
				address: ''
			}
		};
	},
	onLoad: function(option) {
		console.log('111111111111111')
		console.log(option)
		if (option.item) {
			console.log('222222222')
			const item = JSON.parse(decodeURIComponent(option.item));
			this.form = item
			console.log(this.form)
			fetch.request('/index/qiang/recorddetail', item, 'GET').then(res => {
				if (parseInt(res.code) === 0) {
					this.order_info = res.data.order_info;
					this.user_money = res.data.user_money;
				} else {
				}
			});
		} else if (option.record) {
			console.log('333333333333')
			const record = JSON.parse(decodeURIComponent(option.record));
			let order_info = {
				...record.order,
				...record.goods,
				...record.member_address
			};
			
			this.order_info = order_info;
			console.log(this.order_info.order_id)
			this.user_money = record.usableSum;
		}
	},
	methods: {
		submit() {
			fetch
				.request(
					'/index/Qiang/confirm',
					{
						order_id: this.order_info.order_id
					},
					'POST'
				)
				.then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 2000
					});
					if (parseInt(res.code) === 0) {
						setTimeout(() => {
							uni.navigateBack();
						}, 2100);
					}
				});
		}
	}
};
</script>

<style></style>
